package com.study;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.GetResponse;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeoutException;

public class HelloGetConsumer {
    public static void main(String[] args) throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException, IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //指定协议，用户名，密码，host名，指定端口号，指定虚拟主机%2f
        connectionFactory.setUri("amqp://root:123456@192.168.181.131:5672/%2f");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        GetResponse getResponse = channel.basicGet("queue.biz", true);

        byte[] body = getResponse.getBody();
        System.out.println(new String(body));


        channel.close();
        connection.close();

    }
}
